<template>
  <a-card :bordered="false">
    <super-query :fieldList="tableObj.columns" @ok="handleSuperQuery"/>
    <v-table
      bordered
      ref="table"
      :columns="tableObj.columns"
      :data="loadData"
    >
      <template v-slot:buttons>
        <a-button type="primary" icon="plus" @click="$refs.roleForm.init('','add')">新建</a-button>
      </template>
      <span slot="isSystem" slot-scope="{row,text}">
        <span v-if="text == 'Y'">是</span>
        <span v-else>否</span>
      </span>
      <span slot="action" slot-scope="{row,text}">
        <span>
          <a href="javascript:;" @click="edit(row)" :disabled="row.isSystem === 'Y'">编辑</a>
          <a-divider type="vertical" />
        </span>
        <span v-action="'sys:role:del'">
          <a-popconfirm title="是否删除角色" @confirm="deleteItem(row)" okText="是" cancelText="否" >
            <a-icon slot="icon" type="question-circle-o" style="color: red" />
            <a href="javascript:;" style="color: red" :disabled="row.isSystem === 'Y'">删除</a>
          </a-popconfirm>
          <a-divider type="vertical" />
        </span>
        <span v-action="'sys:role:info'">
          <a href="javascript:;"@click="show(row)">查看</a>
          <a-divider type="vertical" />
        </span>
        <span>
          <a href="javascript:;" @click="perms(row)">权限</a>
        </span>
      </span>
    </v-table>
    <role-form
      ref="roleForm"
      @ok="queryPage"
    />
    <role-perm-modal
      ref="rolePermModal"
    />
  </a-card>

</template>

<script>
import { fetchList, delObj } from '@api/sys/role'
import { TableMixin } from '@/mixins/TableMixin'
import { DataScopeTypeList as dsTypeList } from '@/dict'
import { tableObj } from './template'
import roleForm from '@/views/modules/sys/role/roleForm'
import rolePermModal from '@/views/modules/sys/role/rolePermModal'
import SuperQuery from '@comp/SuperQuery/SuperQuery'
export default {
  name: 'Role',
  mixins: [TableMixin],
  components:{
    roleForm,
    SuperQuery,
    rolePermModal
  },
  data () {
    return {
      tableObj,
      dsTypeList,
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    edit (record) {
      this.$refs.roleForm.init(record.id, 'edit')
    },
    deleteItem (record) {
      delObj(record.roleId).then(res => {
        this.$message.info('删除成功')
        this.queryPage()
      })
    },
    show (record) {
      this.$refs.roleForm.init(record.id, 'show')
    },
    perms (record) {
      this.$refs.rolePermModal.init(record)
    }
  }
}
</script>

<style scoped>

</style>
